<template>
<el-container>
<el-main class="padding_top heiauto has_lr">
    <el-form ref="elForm" :model="formData" :rules="rules" size="mini" label-width="130px" label-position="right"
    >
      <el-form-item label="表单指标名称" prop="tiINm">
        <el-input v-model="formData.tiINm" placeholder="请输入表单指标名称" readonly clearable
          :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="名录指标名称" prop="ml_tiINm">
        <el-select v-model="formData.ml_tiINm" placeholder="请选择名录指标名称" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in ml_tiINmOptions" :key="index" :label="item.fieldName"
            :value="item.fieldName" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否为主字段" prop="field104" >
        <el-radio-group v-model="formData.field104" size="medium">
          <el-radio v-for="(item, index) in field104Options" :key="index" :label="item.value"
            :disabled="item.disabled">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否可回写到名录" prop="field105">
        <el-radio-group v-model="formData.field105" size="medium">
          <el-radio v-for="(item, index) in field105Options" :key="index" :label="item.value"
            :disabled="item.disabled">{{item.label}}</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
  </el-main>
  <el-footer class="footer_box" prop="field106" >
     <el-button type="primary" size="mini" @click="saveData"> 保存 </el-button>
  </el-footer>
</el-container>
</template>
<script>
import request from "@/utils/requestutil";
import {getRealUrl, syncRequest} from "@/utils/httpRequet";
import $ from "jquery";
import treeExhide from "@/components/ztree/lib/jquery.ztree.exhide.min.js";
import dicPanel from '@/hr/utils/dicPanel'
import { options } from 'runjs';
import psTree from '@/components/psTree/psTree';
import { isNull } from 'xe-utils/methods';
import functionSelector from '@/components/FunctionSelector/FunctionSelector'
import xspreadsheet from "@/components/x-spreadsheet/xspreadsheet.js";
import "@/components/x-spreadsheet/xspreadsheet.css";
export default {
  components: {},
  props: [],
  data() {
    return {
      val:"",
      formData: {
        tiINm: undefined,
        ml_tiINm: undefined,
        field104: "1",
        field105: "2",
        field106: undefined,
      },
      rules: {
        tiINm: [],
        ml_tiINm: [],
        field104: [],
        field105: [],
      },
      ml_tiINmOptions: [{
        "label": "选项一",
        "value": "1"
      }, {
        "label": "选项二",
        "value": "2"
      }],
      field104Options: [{
        "label": "主字段",
        "value": "1"
      }, {
        "label": "从字段",
        "value": "2"
      }],
      field105Options: [{
        "label": "只读",
        "value": "0"
      }, {
        "label": "可回写",
        "value": "1"
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    writeData(val){
      this.val = val;
      this.formData.tiINm = val.tiCdNnm;
      this.formData.field104 = val.isedit;
      this.formData.field105 = val.isbak;
      this.getMLTiIList(val.bzcode,val.lxCd);
    },
    //查询名录指标名称
    getMLTiIList(bzcode,lxCd){
      //查询要查的表名称
      let that = this;
      request({
        url:"getTabelName",
        method:"post",
        params:{bzcode:bzcode,lxCd:lxCd},
      }).then((data)=>{
        if(data.data.length>0){
          that.getTableFiledList(data.data[0].lxTb);
        }else{
          that.$message.warning("数据库没有配置实体表名称！");
          return false;
        }
      })
    },
    getTableFiledList(tableName){
      request({
        url:"field",
        method:"post",
        data:{tableId:tableName},
      }).then((data)=>{
        this.ml_tiINmOptions = data.data
      })
    },
    saveData(){
      //保存修改的数据
      let that = this;
      if(that.val == "" || that.val.id == "" || that.val.id == undefined){
        return false;
      }else{
        request({
          url:"mlglSave",
          method:"post",
          params:{tiINm:that.formData.tiINm,ml_tiINm:that.formData.ml_tiINm,isedit:that.formData.field104,isbak:that.formData.field105,id:that.val.id}
        }).then((data)=>{
          if(data.data == undefined){
            that.$message.error("服务错误，请联系管理员！");
            return false;
          }
          if(data.data.success == true){
            that.$message.success("修改成功！");
            that.$emit('seachData', that.val.bzcode,that.val.ttId,that.val.tsCd)
          }else{
            that.$message.error("修改失败！");
          }
        })
      }
    }
  }
}

</script>